<%
Dim ad_id
Dim ad_title	
Dim ad_location
Dim ad_url
Dim ad_type
Dim ad_width
Dim ad_height
Function Get_Js()
	dtmNow=Now()
	m_strDate  = Year(dtmNow)&Right("0"&Month(dtmNow),2)&Right("0"&Day(dtmNow),2)
	m_strDate  = m_strDate&Hour(Time())&Minute(Time())&Second(Time())
	m_lngTime  = Clng(Timer()*1000)
	Get_Js		= "/uploadimages/"&m_strDate&m_lngTime&".js"
End Function 
Sub Get_Data()
	ad_title		= reform("ad_title")
	ad_location		= reform("ad_location")	
	ad_url			= reform("ad_url")
	ad_type			= reform("ad_type")
	ad_width		= reform("ad_width")
	ad_height		= reform("ad_height")
	ad_width		= CheckNumeric(ad_width)
	ad_height		= CheckNumeric(ad_height)
	
	Call Check_Length(ad_title,100,1,"广告标题")
	Call Check_Length(ad_location,500,0,"位置说明")
	Call Check_Length(ad_url,100,0,"文件位置")
	Call Check_Length(ad_type,20,0,"广告类型")

End Sub  

Function Add()
		
	Call Get_Data()
	ad_url = Get_Js()
	Sql = "INSERT INTO ad_system(ad_title,ad_location,ad_url,ad_type,ad_width,ad_height)"&_
		  "VALUES("&_
		  "'"& ad_title &"'"&_
		  ",'"& ad_location &"'"&_
		  ",'"& ad_url &"'"&_
		  ",'"& ad_type &"'"&_
		  ","& ad_width &_
		  ","& ad_height &_
		  ")"


	Call Db_Execute("设置",Sql,"ad_system_query.asp")

	

End Function 

Function editsave()

	ad_id	 	 = reform("ad_id")
	Call Check_IsNumeric_Msg(ad_id,"ID")

	Call Get_Data()
	
	Sql = "UPDATE  ad_system SET "&_
		  " ad_title	= '"& ad_title &"'"&_
		  ",ad_location = '"& ad_location &"'"&_
		  ",ad_width	= "& ad_width &_
		  ",ad_height	= "& ad_height &_

		  " WHERE ad_id="&ad_id

	Call Db_Execute("设置",Sql,"ad_system_query.asp")

End Function

Function Del()

	sID = reform("ID")

	Sql = "DELETE FROM ad_system WHERE ad_id IN ("& sID &")"
	Sql = Sql&";DELETE FROM ad_system_Detail WHERE ad_id IN ("& sID &")"

	Call Db_Execute("删除",Sql,"ad_system_query.asp")

End Function 

'************

Dim id				
Dim ad_d_title		
Dim ad_d_image		
Dim ad_d_url		
Dim ad_d_order		

Sub Get_Detail_Data()

	ad_d_title		= reform("ad_d_title")
	ad_d_image		= reform("ad_d_image")	
	ad_d_url		= reform("ad_d_url")	
	ad_d_order		= reform("ad_d_order")

	If Request.ServerVariables ("Request_Method")="POST" Then
		ad_id = reform("ad_id")
	Else
		ad_id = requery("ad_id")
	End If 
	Call Check_IsNumeric_Msg(ad_id,"ID")

	
	Call Check_Length(ad_d_title,100,1,"文字标题")
	Call Check_Length(ad_d_image,200,0,"图片")
	Call Check_Length(ad_d_url,100,0,"文件位置")
	Call Check_IsNumeric_Msg(ad_d_order,"顺序")

End Sub  

Function detail_Add()
		
	Call Get_Detail_Data()
	Sql = "INSERT INTO ad_system_detail(ad_id,ad_d_title,ad_d_image,ad_d_url,ad_d_order)"&_
		  "VALUES("&_
		  "'"& ad_id &"'"&_
		  ",'"& ad_d_title  &"'"&_
		  ",'"& ad_d_image &"'"&_
		  ",'"& ad_d_url &"'"&_
		  ",'"& ad_d_order &"'"&_
		  ")"

	Call Db_Execute("设置",Sql,"ad_system_detail_query.asp?ad_id="&ad_id)

End Function 

Function detail_editsave()

	ad_id	 	 = reform("ad_id")
	Call Check_IsNumeric_Msg(ad_id,"ID")
	id		 	 = reform("id")
	Call Check_IsNumeric_Msg(id,"ID")

	Call Get_Detail_Data()
	
	Sql = "UPDATE  ad_system_detail SET "&_
		  " ad_d_image = '"& ad_d_image &"'"&_
		  ",ad_d_title = '"& ad_d_title &"'"&_
		  ",ad_d_url   = '"& ad_d_url &"'"&_
		  ",ad_d_order = "& ad_d_order &_
		  " WHERE id="&id

	Call Db_Execute("设置",Sql,"ad_system_detail_query.asp?ad_id="&ad_id)

End Function

Function detail_Del()

	sID = reform("ID")

	Sql = "DELETE FROM ad_system_detail WHERE id IN ("& sID &")"

	Call Db_Execute("删除",Sql,"ad_system_detail_query.asp?ad_id="&ad_id)

End Function 
'生成广告文件内容
Sub gen_js()
	sID = reform("ID")
	sID = reform("ID")
	If sID="" Then 
		AlertBox "选择要生成的记录!","javascript:history.go(-1)"
	End If 

	Sql = "SELECT ad_id,ad_url,ad_type,ad_width,ad_height FROM ad_system WHERE ad_id IN ("& sID &")"

	Array_List = GetRsRows(Sql)
	If IsArray(Array_List)=False  Then 
		AlertBox "选择要生成的记录!","javascript:history.go(-1)"
	End If 
	For i=0 To UBound(Array_List,2)
		ad_id	= Array_List(0,i)
		ad_url	= Array_List(1,i)
		ad_type = Array_List(2,i)
		ad_width= Array_List(3,i)
		ad_height= Array_List(4,i)
		'幻灯片,单个图片,单行文字,多行滚动文字
		Select Case ad_type
			Case "幻灯片" Call gen_flas_pic(ad_id,ad_url,ad_width,ad_height)
			Case "单个图片" Call gen_single_pic(ad_id,ad_url,ad_width,ad_height)
			Case "多行滚动文字" Call gen_scroll_text(ad_id,ad_url)
			Case Else writebr "错误"
		End Select 
	Next 
	AlertBox "生成成功!","ad_system_query.asp"
End Sub 
Sub gen_scroll_text(ad_id,ad_url)
	Sql = "SELECT ad_d_title,ad_d_image,ad_d_url FROM ad_system_detail WHERE ad_id ="&ad_id &" ORDER BY ad_d_order ASC"
	Array_List = GetRsRows(Sql)

	If IsArray(Array_List)=False Then 		
		Exit Sub 
	End If 

	ad_content = "document.writeln(""<style type=\""text/css\"">"")"&Chr(10)&_
	"document.writeln(""#scrollDiv{width:400px;height:25px;line-height:25px;border:#ccc 0px solid;overflow:hidden}"")"&Chr(10)&_
	"document.writeln(""#scrollDiv li{height:25px;padding-left:10px;}"")"&Chr(10)&_
	"document.writeln(""</style>"")"&Chr(10)&_

	"function AutoScroll(obj){ "&Chr(10)&_
	"$(obj).find(""ul:first"").animate({"&Chr(10)&_
	"marginTop:""-25px"""&Chr(10)&_
	"},500,function(){"&Chr(10)&_
	"$(this).css({marginTop:""0px""}).find(""li:first"").appendTo(this);"&Chr(10)&_
	"});"&Chr(10)&_
	"}"&Chr(10)&_
	"$(document).ready(function(){"&Chr(10)&_
	"setInterval('AutoScroll(""#scrollDiv"")',5000)"&Chr(10)&_
	"});"&Chr(10)&_

	"document.writeln(""<div id=\""scrollDiv\"">"")"&Chr(10)&_
	"document.writeln(""<ul>"");"&Chr(10)

	For i=0 To UBound(Array_List,2)

		ad_d_title	= Array_List(0,i)
		ad_d_image	= Array_List(1,i)
		ad_d_url	= Array_List(2,i)
		ad_content = ad_content&"document.writeln(""<li><a href=\"""&ad_d_url&"\"" target=\""_blank\"">"&ad_d_title&"</a></li>"");"&Chr(10)

	Next 
	ad_content = ad_content&"document.writeln(""</ul>"");"&Chr(10)&_
	"document.writeln(""</div>"");"&Chr(10)

	Call CreateFile(ad_url,	ad_content)
End Sub 

'flash幻灯片
Sub gen_flas_pic(ad_id,ad_url,a_width,a_height)
	
	Sql = "SELECT ad_d_title,ad_d_image,ad_d_url FROM ad_system_detail WHERE ad_id ="&ad_id &" ORDER BY ad_d_order ASC"
	Array_List = GetRsRows(Sql)

	If IsArray(Array_List)=False Then 		
		Exit Sub 
	End If 


	ad_content = "var v_width ="""&a_width&"px"";"&Chr(10)&_
	"var v_height ="""&a_height&"px"";"&Chr(10)&_
	"var v_border_color=""1px solid #555"";//1px solid #fff/none"&Chr(10)&_
	"var v_background_color=""#fff"";//background-color"&Chr(10)&_
	"var MaxScreen = "&(UBound(Array_List,2)+1)&" ;//AD Count"&Chr(10)&_
	"var CurScreen = 1 ;"&Chr(10)&_

	"document.writeln(""<div class=\""lafotViso\"">"");"&Chr(10)


	For i=0 To UBound(Array_List,2)

		ad_d_title	= Array_List(0,i)
		ad_d_image	= Array_List(1,i)
		ad_d_url	= Array_List(2,i)
		ad_content = ad_content&"document.writeln(""  <p id=\""Switch_"&(i+1)&"\""><a href=\"""&ad_d_url&"\"" target=\""_blank\""><img src=\"""&ad_d_image&"\"" alt=\"""&ad_d_title&"\""/></a></p>"");"&Chr(10)

	Next 

	ad_content = ad_content&"document.writeln(""  <ul id=\""SwitchNav\""></ul>"");"&Chr(10)&_
	"document.writeln(""</div>"");"&Chr(10)&_
	"var refreshSwitchTimer = null;"&Chr(10)&_
	"switchPic(CurScreen);"&Chr(10)&_
	"refreshSwitchTimer = setTimeout('reSwitchPic();', 5000);"&Chr(10)&_

	"document.writeln(""<style type=\""text/css\"">"");"&Chr(10)&_
	"document.writeln("".lafotViso {position:relative;width:""+v_width+"";height:""+v_height+"";margin:0 auto;border:""+v_border_color+"";overflow:hidden;text-align:left;background:""+v_background_color+"";}"");"&Chr(10)&_
	"document.writeln("".lafotViso p img {display: block;width:""+v_width+"";height:""+v_height+"";}"");"&Chr(10)&_
	"document.writeln("".lafotViso ul {position:absolute;right:0px;bottom:0px;padding-left:47px;_padding-left:46px;background:url(/images/flashPage_bg.png) 0 0 no-repeat;z-index:2;_background:none;_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\""/images/flashPage_bg.png\"", sizingMethod=\""crop\"");list-style:none;overflow:auto;zoom:1;}"");"&Chr(10)&_
	"document.writeln("".lafotViso ul li {float:left;width:15px;height:18px;line-height:18px;text-align:center;margin-left:1px;background:#000;display:inline;}"");"&Chr(10)&_
	"document.writeln("".lafotViso ul li a {display:block;width:15px;height:18px;font-size:10px;font-family:Tahoma;font-weight:bold;color:#fff;}"");"&Chr(10)&_
	"document.writeln("".lafotViso ul li a:hover, .lafotViso ul li a.sel {color:#F20000;}"");"&Chr(10)&_
	"document.writeln(""</style>"");"&Chr(10)

	Call CreateFile(ad_url,	ad_content)
End Sub 
Sub gen_single_pic(ad_id,ad_url,ad_width,ad_height)
	Sql = "SELECT ad_d_title,ad_d_image,ad_d_url FROM ad_system_detail WHERE ad_id ="&ad_id &" ORDER BY ad_d_order ASC"
	Array_List = GetRsRows(Sql)

	If IsArray(Array_List)=False Then 		
		Exit Sub 
	End If 
	ad_d_title	= Array_List(0,0)
	ad_d_image	= Array_List(1,0)
	ad_d_url	= Array_List(2,0)
	If CheckNumeric(ad_width)=0 Or CheckNumeric(ad_height)=0 Then 
		wh = ""
	Else
		wh = "width=\"""&ad_width&"px\"" height=\"""&ad_height&"px\"""
	End If 

	ad_content = "document.writeln(""<a href=\"""&ad_d_url&"\""><img src=\"""&ad_d_image&"\"" "&wh&" /></a>"")"
	
	Call CreateFile(ad_url,	ad_content)
End Sub 
Sub CreateFile (filename,content)
	save_filename = server.mappath(filename)
	Set objStream = CreateObject("ADODB.Stream")
	With objStream
		.Open
		.Charset = "utf-8"
		.Position = objStream.Size
		.WriteText= content
		.SaveToFile save_filename,2 
		.Close
	End With
	Set objStream = Nothing
End Sub 
%>